﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pb;

public class PlayerListPanel : MonoBehaviour {

    public GameObject grid;
    public GameObject playerItemPre;
    public List<PaiPlayer> playerList;
    public GameObject closeBtn;

	void Start () {
        UIEventListener.Get(closeBtn).onClick = ButtonClick;
        LogMsg();
	}

    void ButtonClick(GameObject button)
    {
        if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
        }
    }

    void LogMsg()
    {
        Debug.Log("房间内的玩家数量：" + playerList.Count);
        for (int i = 0; i < playerList.Count;i++ )
        {
            GameObject player = Instantiate(playerItemPre);
            player.transform.SetParent(grid.transform);
            player.transform.localScale = Vector3.one;
            player.transform.localPosition = Vector3.zero;
            XTJPlayerItem playerItem = player.GetComponent<XTJPlayerItem>();
            playerItem.nameLabel.text = playerList[i].Nickname;
            playerItem.goldLabel.text = EginUser.Instance.ReturnMoneyForLong(playerList[i].Coin);
            if(playerList[i].AvatarUrl != ""){
                WXAvatarManager._instance.GetWxAvatar(playerList[i].Id,playerItem.wxAvatar,playerList[i].AvatarUrl);
                playerItem.wxAvatar.gameObject.SetActive(true);
            }
            else
            {
                playerItem.avatar.spriteName = playerList[i].AvatarId.ToString();
            }

            grid.GetComponent<UIGrid>().enabled = true;
        }
    }
	
}
